﻿using PKTools.Database;
using PKTools.SqlObjects;
//using PKTools.SqlObjects;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
// Krzysztof Heim
// pktools.codeplex.com

namespace PKTools.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            // test fast serializer
            //var
            //    dict = new Dictionary<Guid, object>();
            //var
            //    r = new Random();
            //var
            //    testObjects = new FastSerializer().GetTestObjects();

            //for (int i = 0; i < 100000; i++)          
            //    dict.Add(Guid.NewGuid(), testObjects[r.Next(testObjects.Length)]);

            //byte[]
            //    buf = null;

            //using (new Stoper("FS serialize", () => buf.Length.ToString()))
            //    buf = new FastSerializer().ToBytes(dict);

            //using (new Stoper("FS deserialize"))
            //    new FastSerializer().FromBytes(buf);

            //using (new Stoper("BS serialize", () => buf.Length.ToString()))
            //using (var ms = new MemoryStream())
            //{
            //    new BinaryFormatter().Serialize(ms, dict);
            //    buf = ms.ToArray();
            //}

            //using (new Stoper("BS deserialize"))
            //using (var ms = new MemoryStream(buf))
            //    new BinaryFormatter().Deserialize(ms); 

            //// test replace CI
            //if ("Abc abc ABC".ReplaceCI("abc", "123") != "123 123 123")
            //    throw new Exception("ReplaceCI failed");

            using (var sql = new MsSql())
            {
                var
                    record = SfScreenRevision.LoadByPK(sql, 108);
            }
          
            // test sql
           /* Dummy
                temp = null;

            Transaction.Block<MsSql>(sql =>
            {
                sql.ExecuteNonQuery("DELETE Dummy");

                var
                    record = new Dummy
                    {
                        Container = "L1000",
                        ProductID = 10,
                        Status = 1,
                        Active = true,
                        CreatedOn = DateTime.Now
                    };

                record.Insert(sql);

                temp = Dummy.LoadByPK(sql, "L1000", 10);

                temp.Active = false;

                temp.Update(sql);
            });

            Transaction.Block<MsSql>(sql =>
            {
                temp.Active = true;
                temp.Update(sql, false);
            });*/
        }
    }
}
